<?php 
/**
 * The settings panel is based on the code of the tarski theme (http://tarskitheme.com/)
 * by Ben Eastaugh and Chris Sternal-Johnson.
 *
 * @package dkret3
 * @since 3.6
 */

$data = get_theme_data( STYLESHEETPATH . '/style.css' );
?>

<div id="dkret-settings" class="wrap metabox-holder <?php if ( get_bloginfo( "text_direction" ) == "rtl" ) : echo " rtl"; endif; ?>">

    <form action="<?php echo admin_url( 'admin-post.php?action=dkret_update_options' ); ?>" method="post">
        <?php wp_nonce_field( 'theme-settings' ); ?>
        
        <div id="dkret-settings-header">

            <?php screen_icon(); ?>
            <h2><?php printf( __( '%s Settings', 'dkret' ), esc_attr( $data['Name'] ) ); ?></h2>
            
            <p id="dkret-save-settings">
                <input type="submit" class="button-primary" name="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>" />
            </p>

            <p id="dkret-info">
                <a href="<?php esc_attr_e( $data['URI'] ); ?>"><?php _e( 'Download dkret3', 'dkret'); ?></a>
            </p>
        
            <div class="clearer"></div>
        </div>

        <?php if ( isset( $_GET['updated'] ) ) : ?>
            <div class="updated fade below-h2">
                <p><?php printf( __( 'Settings saved. %s', 'dkret' ),'<a href="' . user_trailingslashit( get_bloginfo( 'url' ) ) . '">' . __( 'View site &rsaquo;', 'dkret' ) . '</a>' ); ?></p>
            </div>
        <?php elseif ( isset( $_GET['defaults'] ) ) : ?>
            <div class="updated fade below-h2">
                <p><?php printf( __( 'Defaults loaded. %s', 'dkret' ),'<a href="' . user_trailingslashit( get_bloginfo( 'url' ) ) . '">' . __( 'View site &rsaquo;', 'dkret' ) . '</a>' ); ?></p>
            </div>
        <?php endif; ?>

        <div class="span">
            <div class="postbox">
                <h3 class="hndle"><?php printf( __( 'About %s', 'dkret' ), esc_attr( $data['Name'] ) ); ?></h3>
                <div class="inside">

                    <p class="theme_information">
                        <?php printf( __( '<strong>Version:</strong> %s', 'dkret' ), esc_attr( $data['Version'] ) ) ; ?>
                        <br />
                        <?php printf( __( '<strong>Author:</strong> %s', 'dkret' ), $data['Author'] ); ?>
                    </p>

                    <?php if ( ! is_child_theme() ) : ?>
                        <p><?php _e( 'The dkret3 theme is flexible theme framework for WordPress developed by <a href="http://diekretzschmars.de/">Joern Kretzschmar</a>.', 'dkret' ) ?></p>
                        <p><?php _e( 'Get support at the <a href="http://wordpress.org/support/forum/themes-and-templates">official WordPress forum</a>.', 'dkret' ); ?></p>
                    <?php else : ?>                    
                        <p><?php echo $data['Description']; ?></p>
                        <p><?php _e( 'Get support at the <a href="http://wordpress.org/support/forum/themes-and-templates">official WordPress forum</a>.', 'dkret' ); ?></p>
                    <?php endif; ?>

                </div>
            </div>
        </div>
    
        <div class="primary">
            <div class="postbox">
                <h3 class="hndle"><?php _e( 'Header', 'dkret' ); ?></h3>
                <div class="inside">
                    <div class="option borderless">
                        <?php
                            $image = HEADER_IMAGE;
                                
                            if ( dkret_random_header_image() != '0' )
                                $image = THEME_URI . '/library/images/headers/random-thumbnail.jpg';
                        ?>

                        <?php if ( get_theme_mod( 'header_textcolor' ) != 'blank' && !defined( 'NO_HEADER_TEXT' ) ) : ?>
                            <div class="title" style="color: #<?php header_textcolor(); ?>;"><?php bloginfo( 'blogtitle' ); ?></div>
                        <?php endif; ?>
                        
                        <label for="recent-header-image">
                            <img name="recent_header" id="recent-header-image" src="<?php echo $image ?>" alt="" width="350" />
                       </label>
                    </div>

                    <div class="suboption">
                        <label for="opt-header-link">
                            <input name="header_link" id="opt-header-link" type="checkbox" <?php if( get_dkret_option( 'header_link' ) ) echo 'checked="checked"'; ?> value="true"  />
                            <?php _e( 'Link header image to blog home', 'dkret' ); ?>
                        </label>
                    </div>
                    
                    <div class="details">
                        <p><?php printf( __('You can upload and delete a header image on the <a href="%s">Custom Header Page</a>.', 'dkret' ),
                                    get_bloginfo( 'url' ) . '/wp-admin/themes.php?page=custom-header' ); ?></p>
                        <p><?php _e( "Header images (.gif, .jpg or .png) uploaded to <code>wp-content/uploads/headers/</code> will be displayed randomly.", 'dkret' ); ?></p>
                    </div>

                </div>
            </div>
        </div>

        <div class="secondary">
            <div class="postbox">
                <h3 class="hndle"><?php _e( 'Gallery', 'dkret' ); ?></h3>
                <div class="inside">
                    <div class="option borderless">
                        <?php wp_dropdown_categories( array(
                            'hide_empty' => 0,
                            'name' => 'gallery_cat_id',
                            'selected' => get_dkret_option( 'gallery_cat_id' ),
                            'show_option_none' => __( 'No Gallery', 'dkret' ),
                            'hide_empty' => 0,
                            'orderby' => 'name',
                            'show_count' => 0,
                            'hierarchical' => 1) ); ?>
                        <p><?php _e('First choose a <strong>gallery category</strong>.', 'dkret' ); ?></p>
                    </div>
                    <div class="suboption">
                        <label for="opt-gallery-link">
                            <input name="gallery_link" id="opt-gallery-link" type="checkbox" <?php if( get_dkret_option( 'gallery_link' ) ) echo 'checked="checked"'; ?> value="true"  />
                            <?php _e( 'Show the Gallery Link', 'dkret' ); ?>
                        </label>
                    </div>
                    <div class="details">
                        <p><?php _e( "Asign a category to all posts with embedded galleries and choose this <strong>gallery category</strong> in the list above for a nice gallery view of these posts.", 'dkret' ); ?></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="primary">
            <div class="postbox">
                <h3 class="hndle"><?php _e( 'Navigation', 'dkret' ); ?></h3>
                <div class="inside">
                    <div class="option borderless">
                        <label for="opt-nav-homename"><?php _e( 'Rename your &#8216;Home&#8217; link', 'dkret' ); ?></label>
                        <input type="hidden" name="home_link_name" value="Home" />
                        <input class="text" type="text" id="opt-nav-homename" name="home_link_name" value="<?php esc_attr( dkret_option( 'home_link_name' ) ); ?>" />
                        <p><?php _e( "This link is not displayed when you don't set a text for it.", 'dkret' ); ?></p>
                    </div>
                    <div class="option">
                        <label for="opt-show-navigation">
                            <input name="show_navigation" id="opt-show-navigation" type="checkbox" <?php if( get_dkret_option( 'show_navigation' ) ) echo 'checked="checked"'; ?> value="true" />
                            <?php _e('Show the Navigation','dkret') ?>
                        </label>
                    </div>
                    <div class="option borderless">
                        <label for="opt-rss-link">
                            <input name="rss_link" id="opt-rss-link" type="checkbox" <?php if( get_dkret_option( 'rss_link' ) ) echo 'checked="checked"'; ?> value="true"  />
                            <?php _e( 'Show the RSS-Link', 'dkret' ); ?>
                        </label>
                    </div>
                    <div class="details">
                        <p><?php printf( __( 'You can add pages, categories and static links to the navigation at the <a href="%1$s" title="Menu">Menu Page</a>.', 'dkret' ),
                                    get_bloginfo( 'url' ) . '/wp-admin/nav-menus.php' ); ?></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="secondary">
            <div class="postbox">
                <h3 class="hndle"><?php _e( 'Miscellaneous Options', 'dkret' ); ?></h3>
                <div class="inside">
                    <label for="opt-preview-comments">
                        <input name="preview_comments" id="opt-preview-comments" type="checkbox" <?php if( get_dkret_option( 'preview_comments' ) ) echo 'checked="checked"'; ?> value="true"  />
                        <?php _e( 'Show Comment Preview', 'dkret' ); ?>
                    </label>
                    <label for="opt-validate-comments">
                        <input name="validate_comments" id="opt-validate-comments" type="checkbox" <?php if( get_dkret_option( 'validate_comments' ) ) echo 'checked="checked"'; ?> value="true"  />
                        <?php _e( 'Validate Commentform', 'dkret' ); ?>
                    </label>
                    <label for="opt-remove-meta-info">
                        <input name="remove_meta_information" id="opt-remove-meta-information" type="checkbox" <?php if( get_dkret_option( 'remove_meta_information' ) ) echo 'checked="checked"'; ?> value="true"  />
                        <?php _e( 'Remove WordPress meta info', 'dkret' ); ?>
                    </label>
                    <label for="opt-summary">
                        <input name="summary" id="opt-summary" type="checkbox" <?php if( get_dkret_option( 'summary' ) ) echo 'checked="checked"'; ?> value="true"  />
                        <?php _e( 'Show search and archive pages as Summary', 'dkret' ); ?>
                    </label>
                    <label for="opt-remove-settings">
                        <input name="remove_settings" id="opt-remove-settings" type="checkbox" <?php if( get_dkret_option( 'remove_settings' ) ) echo 'checked="checked"'; ?> value="true"  />
                        <?php _e( 'Remove all settings after theme switch', 'dkret' ); ?>
                    </label>
                    <div class="details">
                        <p><?php _e( "You should check the last option only if you permanently want to delete the theme.", 'dkret' ); ?></p>
                    </div>
                </div>
            </div>
        </div>

        <?php
            $layout_dir = @ dir( CHILD_THEME_DIR . '/library/layouts' );

            if ( ! empty( $layout_dir ) ) :
                while( ( $file = $layout_dir->read() ) !== false ) :
                    if ( !preg_match( '|^\.+$|', $file ) && preg_match( '|\.css$|', $file ) ) 
                        $layout_files[] = $file;
                endwhile;
            endif;
            
            if ( ! empty ( $layout_files ) ) :
        ?>
        
            <div class="primary">
                <div class="postbox">
                    <h3 class="hndle"><?php _e( 'Alternate Layout', 'dkret' ); ?></h3>
                    <div class="inside">
                        <div class="option borderless">
                            <select name="layout_file" id="opt-layout-file" size="true">
                                <option value="<?php esc_attr( dkret_option( 'layout_file' ) ); ?>"><?php if ( get_dkret_option( 'layout_file' ) == 'Default-Layout' ) _e( 'Default Layout', 'dkret' ); else dkret_option( 'layout_file' ); ?></option>
                                <option value="Default-Layout"><?php _e( 'Default Layout', 'dkret' ); ?></option>
                                <?php                                 
                                    foreach( $layout_files as $layout_file ) :
                                        echo '<option value="' . esc_attr( $layout_file ) . '">' . esc_attr ( $layout_file ) . '</option>';
                                    endforeach;
                                ?>
                                
                            </select>
                            <p><?php _e( 'Choose your prefered layout.', 'dkret' ); ?></p>
                        </div>
                        <div class="details">
                            <p><?php _e( 'Layout files visually customize the default layout. Choose from the list above.', 'dkret' ); ?></p>
                        </div>                        
                    </div>
                </div>
            </div>
            
        <?php endif; ?>

        <div class="span">
            <div class="postbox">
                <h3 class="hndle"><?php _e( 'Footer Text', 'dkret' ); ?></h3>
                <div class="inside">
                    <div class="option footer-text borderless">
                        <label for="opt-footer-text">
                            <p><textarea class="widefat" rows="2" cols="30" id="opt-footer-text" name="footer_text"><?php echo get_dkret_option( 'footer_text' ); ?></textarea></p>
                        </label>
                    </div>
                    <div class="details">
                        <p>
                            <?php _e( "Add Text or HTML Code and use the following Shortcodes for convenient adjustments:", 'dkret'); ?>
                            <br/>
                            <span><code>[theme-link]</code> <code>[child-link]</code> <code>[theme-version]</code> <code>[child-version]</code> <code>[wp-link]</code> <code>[site-link]</code> <code>[the-year]</code> <code>[check-html]</code> <code>[check-css]</code> <code>[query-count]</code> <code>[separator]</code>.</span>
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <div class="span">
            <div class="postbox">
                <h3 class="hndle"><?php _e( 'Google AdSense', 'dkret' ); ?></h3>
                <div class="inside">
                    <div class="option adsense-block borderless">
                        <label for="opt-adsense-block-1">
                            <p><textarea class="widefat" rows="4" cols="30" id="opt-adsense-block-1" name="adsense_block_1"><?php echo get_option( 'dkret_adsense_block_1' ); ?></textarea></p>
                            <p><?php _e( '<strong>Block 1</strong>: Leaderboard Code', 'dkret' ); ?></p>
                        </label>
                    </div>
                    <div class="option adsense-block borderless">
                        <label for="opt-adsense-block-2">
                            <p><textarea class="widefat" rows="4" cols="30" id="opt-adsense-block-2" name="adsense_block_2"><?php echo get_option( 'dkret_adsense_block_2' ); ?></textarea></p>
                            <p><?php _e( '<strong>Block 2</strong>: AdSense Widget [WIDGET]', 'dkret' ); ?></p>
                        </label>
                    </div>
                    <div class="option adsense-block borderless">
                        <label for="opt-adsense-block-3">
                            <p><textarea class="widefat" rows="4" cols="30" id="opt-adsense-block-3" name="adsense_block_3"><?php echo get_option( 'dkret_adsense_block_3' ); ?></textarea></p>
                            <p><?php _e( '<strong>Block 3</strong>: Posts [SHORTCODE default]', 'dkret' ); ?></p>
                        </label>
                    </div>
                    <div class="option adsense-block borderless">
                        <label for="opt-adsense-block-4">
                            <p><textarea class="widefat" rows="4" cols="30" id="opt-adsense-block-4" name="adsense_block_4"><?php echo get_option( 'dkret_adsense_block_4' ); ?></textarea></p>
                            <p><?php _e( '<strong>Block 4</strong>: Posts [SHORTCODE]', 'dkret' ); ?></p>
                        </label>
                    </div>
                    <div class="option adsense-block borderless">
                        <label for="opt-adsense-block-5">
                            <p><textarea class="widefat" rows="4" cols="30" id="opt-adsense-block-5" name="adsense_block_5"><?php echo get_option( 'dkret_adsense_block_5' ); ?></textarea></p>
                            <p><?php _e( '<strong>Block 5</strong>: Posts [SHORTCODE]', 'dkret' ); ?></p>
                        </label>
                    </div>
                    <div class="option adsense-block borderless">
                        <label for="opt-adsense-block-6">
                            <p><textarea class="widefat" rows="4" cols="30" id="opt-adsense-block-6" name="adsense_block_6"><?php echo get_option( 'dkret_adsense_block_6' ); ?></textarea></p>
                            <p><?php _e( '<strong>Block 6</strong>: Posts [SHORTCODE]', 'dkret' ); ?></p>
                        </label>
                    </div>
                    <div class="clearer"></div>
                    <div class="suboption">
                        <label for="opt-hide-adsense">
                            <input name="hide_adsense" id="opt-hide-adsense" type="checkbox" <?php if( get_dkret_option( 'hide_adsense' ) ) echo 'checked="checked"'; ?> value="true"  />
                            <?php _e( 'Hide Advertisments for logged in users', 'dkret' ); ?>
                        </label>
                        <label for="opt-adsense-before">
                            <input name="adsense_before" id="opt-adsense-before" type="checkbox" <?php if( get_dkret_option( 'adsense_before' ) ) echo 'checked="checked"'; ?> value="true"  />
                            <?php _e( 'Insert AdSense <strong>Block 3</strong> to post header', 'dkret' ); ?>
                        </label>
                        <label for="opt-adsense-after">
                            <input name="adsense_after" id="opt-adsense-after" type="checkbox" <?php if( get_dkret_option( 'adsense_after' ) ) echo 'checked="checked"'; ?> value="true"  />
                            <?php _e( 'Insert AdSense <strong>Block 4</strong> to post bottom', 'dkret' ); ?>
                        </label>

                    </div>
                    <div class="details">
                        <p><?php _e( "Paste your Google AdSense Code to the textareas above. Leave them free if you don't use AdSense.", 'dkret' ); ?></p>
                        <p><?php printf( __( 'Use the dkret <a href="%1$s">AdSense Widget</a> to add <strong>Block 2</strong> to your Sidebars.', 'dkret' ),
                                    get_bloginfo( 'url' ) . '/wp-admin/widgets.php' ); ?></p>
                        <p><?php _e( "Use the <code>[adsense]</code> shortcode to add <strong>Block 3</strong> to your post. To right align advertisments use <code>[adsense align=\"alignright\"]</code> and <code>[adsense align=\"aligncenter\"]</code> to center them. You can add the ID option <code>[adsense id=\"2\"]</code> to display other <strong>Blocks</strong>.", 'dkret' ); ?></p>
                    </div>
                </div>
            </div>
            
            <p>
                <input type="submit" class="button-primary" name="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>" />
                <input type="submit" class="button-secondary" name="restore-defaults" value="<?php esc_attr_e( 'Revert to Theme Defaults', 'dkret' ); ?>" />
            </p>
        </div>
    </form>

    <div class="clearer"></div>
</div>